package web.servlets;

import java.io.IOException;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ejb.entity.DBImage;
import ejb.manager.DBImageManager;


/**
 * Servlet implementation class ImageServlet
 */
@WebServlet(name = "Image", urlPatterns = { "/Image" })
public class ImageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	@EJB
	private DBImageManager imagemanager;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ImageServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String name = request.getParameter("name");
		DBImage image;

		image = imagemanager.getImage(name);
		response.setContentType(image.getContentType());
		response.getOutputStream().write(image.getImg());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
